module tb_add_vector();


   
   logic [63:0] diff;
   logic [7:0] 	borrows;
   logic [63:0] a, b;
   logic [3:0] 	mode;
   // one 64+64, two 32+32, four 16+16, eight 8+8
   sub_vector #(.width(64), .granu(8)) U_sub_vector (
   													 // Outputs
   													 .o_diff			(diff[63:0]),
   													 .o_borrows			(borrows[7:0]),
   													 // Inputs
   													 .i_a				(a[63:0]),
   													 .i_b				(b[63:0]),
   													 .i_mode			(mode) );
   
   
   
   initial
   	 begin
   		logic [31:0] u32a, u32b, u32;
   		logic [63:0] u64a, u64b, u64;
   		logic 		 borrow;
   		logic [7:0]  borrows_test;
		
		
   		$display("==================== test 64-bit mode ====================");
   		mode = 4'b1000; 		// 64-bit adder
   		for(int i=0;i<1000;i++)
   		  begin
   			 a = {$random, $random};
   			 b = {$random, $random};
   			 {borrow, u64} = a - b;
   			 #1;
   			 $display("%d - %d = %d (%x), borrow is %d  => correct diff:%x, borrow:%d => %s", 
   					  a, b, diff, diff, borrows[7],
   					  u64, borrow,
   					  {borrows[7], diff} === {borrow, u64} ? "equal" : "Not Equal"
   					  );
			 if({borrows[7], diff} !== {borrow, u64})
   			   begin
   				  $display("failed");
   				  $finish;
   			   end
   		  end // for (int i=0;i<1000;i++)
   		$display("==================== passed ====================");
		

   		$display("==================== test 32-bit mode ====================");
   		mode = 4'b0100; 		// 32-bit adder
   		for(int i=0;i<1000;i++)
   		  begin
   			 a = {$random, $random};
   			 b = {$random, $random};
   			 {borrows_test[0], u64[31:0] } = a[31:0] - b[31:0];
   			 {borrows_test[1], u64[63:32]} = a[63:32] - b[63:32];
   			 #1;
   			 if(!((diff === u64) && ({borrows[7], borrows[3]} === borrows_test[1:0])))
   			   begin
   				  $display("failed");
   				  $finish;
   			   end
   		  end // for (int i=0;i<1000;i++)
   		$display("==================== passed ====================");


   		$display("==================== test 16-bit mode ====================");
   		mode = 4'b0010; 		// 16-bit adder
   		for(int i=0;i<1000;i++)
   		  begin
   			 a = {$random, $random};
   			 b = {$random, $random};
   			 {borrows_test[0], u64[15:0]} = a[15:0] - b[15:0];
   			 {borrows_test[1], u64[31:16]} = a[31:16] - b[31:16];
   			 {borrows_test[2], u64[47:32]} = a[47:32] - b[47:32];
   			 {borrows_test[3], u64[63:48]} = a[63:48] - b[63:48];
   			 #1;
   			 if( !((diff === u64) && ({borrows[7], borrows[5], borrows[3], borrows[1]} === borrows_test[3:0])) )
   			   begin
   				  $display("failed");
   				  $finish;
   			   end
   		  end
   		$display("==================== passed ====================");


   		$display("==================== test 8-bit mode ====================");
   		mode = 4'b0001; 		// 8-bit adder
   		for(int i=0;i<1000;i++)
   		  begin
   			 a = {$random, $random};
   			 b = {$random, $random};
   			 {borrows_test[0], u64[7:0]} = a[7:0] - b[7:0];
   			 {borrows_test[1], u64[15:8]} = a[15:8] - b[15:8];
   			 {borrows_test[2], u64[23:16]} = a[23:16] - b[23:16];
   			 {borrows_test[3], u64[31:24]} = a[31:24] - b[31:24];
   			 {borrows_test[4], u64[39:32]} = a[39:32] - b[39:32];
   			 {borrows_test[5], u64[47:40]} = a[47:40] - b[47:40];
   			 {borrows_test[6], u64[55:48]} = a[55:48] - b[55:48];
   			 {borrows_test[7], u64[63:56]} = a[63:56] - b[63:56];

   			 #1;
   			 if(!((diff === u64) && (borrows===borrows_test)))
   			   begin
   				  $display("failed");
   				  $finish;
   			   end
   		  end // for (int i=0;i<1000;i++)
   		$display("==================== passed ====================");
		
   	 end
endmodule // tb_add_vector
